﻿Chenxin.UI.entrustinfoManage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/trusthandler.ashx',
    createGrid: function() {
        return new Chenxin.UI.Pagination({
            actionUrl: this.actionUrl + '?op=getlist',
            domId: 'page',
            data: {},
            render: function(data) {
                document.getElementById('entrust_table').innerHTML = data;
            }
        });
    },
    loadkeyinfo: function() {
        var _this = this;
        _this.renderHouseInfo();
        _this.createKeyUseList(this.currentId);
    },
    loadInfo: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data.model) {
                    _this.entrustInfo = data.model;
                    _this.showCommission();
                }
            }
        });
    },
    cancle: function() {
    },
    initEvent: function() {
        var _this = this;
        //查看
        $('.a_commission_view').live('click', function() {
            _this.currentId = this.name;
            _this.loadInfo();
        });
        //修改
        $('.a_commission_edit').live('click', function() {
            _this.currentId = this.name;
            _this.loadInfo();
        });
        //删除
        $('.a_commission_del').live('click', function() {
            _this.currentId = this.name;
            _this.loadInfo();
        });
        //作废
        $('.a_commission_invalid').live('click', function() {
            _this.currentId = this.name;
            _this.loadInfo();
        });
        //恢复
        $('.a_commission_resume').live('click', function() {
            _this.currentId = this.name;
            _this.loadInfo();
        });
    },
    createSearch: function() {
        return new Chenxin.UI.entrustinfoSearch({
            scope: this
        });
    },
    showCommission: function() {
        var _this = this;
        if (!this.currentId) {
            alert('请先选择一条房源记录！');
            return;
        }

        if (!this.commissionWin) {

            var _this = this;
            this.commissionWin = new Chenxin.UI.CommissionForm({
                currentId: this.currentId,
                scope: this,
                afterGetFormJson: function(json) {

                    json.HouseId = _this.entrustInfo.HouseId;
                    json.Employee = this.employeeId.getText();
                    json.EmpDepart = this.empDepartId.getText();
                }
            });
        }
        this.commissionWin.show();
        this.commissionWin.fitData({
            HouseCode: this.entrustInfo.HouseCode,
            HouseAddress: this.entrustInfo.Address
        })
        this.commissionWin.currentId = this.currentId;
    },
    initComponent: function() {
        Chenxin.UI.entrustinfoManage.superclass.initComponent.call(this);
    }
});


/**
*查询面板
*/
Chenxin.UI.entrustinfoSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'entrust_search',
    initEvent: function() {
        var _this = this;
        $('#btn_search').click(function() {
            _this.scope.reloadGrid();
        });
    },
    createComboList: function() {
            var region=new Chenxin.UI.ParameterCombo({
			name:'region',
			containerId:'#region',
			key:'System.Region',
			tbxWidth:45,
			inModelType:'txt'
			});
            var business = new Chenxin.UI.Combo({
                containerId: '#business',
                tbxWidth: 45,
                items: comboCommon.trustBusinessType
            });
            var status = new Chenxin.UI.Combo({
                containerId: '#status',
                tbxWidth: 45,
                items: comboCommon.trustStatus
            });
            var combl = new Chenxin.UI.StructComboList();
            var structs = combl.comboList;
            structs.push(status);
			structs.push(region);
			structs.push(business);
            return structs;
    },
    initComponent: function() {
        Chenxin.UI.entrustinfoSearch.superclass.initComponent.call(this);
    }
});

/**
*备案
*/
Chenxin.UI.RecordForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/markedHandler.ashx',
    id: 'recordWin',
    renderTo: 'jqm_record',
    initFormValidator: function() {
        var _this = this;
        $("#markedTime").formValidator({ validatorgroup: this.id,
            onshow: "请输入时间！", onfocus: "请输入时间", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "时间不能为空!" }, onerror: "时间不能为空!"
        });
        $("#markedNumber").formValidator({ validatorgroup: this.id, onshow: "请输备案号", onfocus: "请输备案号", oncorrect: "输入正确" }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "" }, onerror: "备案号不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) { return val.isNum(); }, onerror: "请输入数字"
        }).ajaxValidator({
            url: "service/markedHandler.ashx",
            datatype: "json",
            data: "houseid=" + _this.currentId + "&op=validate",
            success: function(data) {
                if (data.success == 0) {
                    return false;
                } else {
                    return true;
                }
            },
            buttons: $("#markedSubmitButton"),
            error: function() { alert("服务器没有返回数据，可能服务器忙，请重试"); },
            onerror: "备案号已存在！",
            onwait: "正在校验，请稍候..."
        });
        $("#markEndDay").formValidator({ validatorgroup: this.id,
            onshow: "请输入时间！", onfocus: "请输入时间", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "时间不能为空!" }, onerror: "时间不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                if ($("#markStartDay").val() != "" && $("#markEndDay").val() != "") {
                    var d1 = new Date(Date.parse($("#markStartDay").val().replace(/-/g, "/")));
                    var d2 = new Date(Date.parse($("#markEndDay").val().replace(/-/g, "/")));
                    if ((d1.getTime() - d2.getTime()) > 0) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }, onerror: "开始时间不能大于结束时间"
        });
        $("#markStartDay").formValidator({ validatorgroup: this.id,
            onshow: "请输入时间！", onfocus: "请输入时间", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "时间不能为空!" }, onerror: "时间不能为空!"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                if ($("#markStartDausy").val() != "" && $("#markEndDay").val() != "") {
                    var d1 = new Date(Date.parse($("#markStartDay").val().replace(/-/g, "/")));
                    var d2 = new Date(Date.parse($("#markEndDay").val().replace(/-/g, "/")));
                    if ((d1.getTime() - d2.getTime()) > 0) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }, onerror: "开始时间不能大于结束时间"
        });
    },
    createForm: function() {
        return formCommon.houseRecordForm('changeconfirmation');
    },
    initEvent: function() {
        var _this = this;
        $('#changeconfirmation_Save').live('click', function() {
            _this.save();
        });
        $('#changeconfirmation_Cancle').live('click', function() {
            _this.hide();
        });
    },
    initComponent: function() {
        Chenxin.UI.RecordForm.superclass.initComponent.call(this);
    }
});


$(document).ready(function() {
    var entrustdMgr = new Chenxin.UI.entrustinfoManage();
});





